﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core;

namespace Cofe.Data
{
    [Export(typeof(ICofeService))]
    [ServicePriority(ServicePriorityAttribute.DefaultPriority_COFEDB)]
    public class DBVolumeChangedBehavior : IVolumeChangedBehavior
    {
        public void NotifyAdded(Core.Interfaces.IVolume volume)
        {            
            var rootPPs = volume.DirectoryLister.GetRootPropertyProviders();

            if (rootPPs.Count() > 0)
            {
                var rootPhs = (from rootPP in rootPPs select CofeServices.EntryConstructor.ConstructPropertyHost(rootPP)).ToArray();
                //using (var r = CofeDBServices.RepositoryFactory.CreateRepository())
                //{
                //    r.AddOrUpdate(true, false, rootPhs);
                //    r.SaveChanges();
                //}
            }
        }

        public void NotifyRemoved(Core.Interfaces.IVolume volume)
        {
            //var rootPPs = volume.DirectoryLister.GetRootPropertyProviders();

            //if (rootPPs.Count() > 0)
            //{
            //    var rootPhs = (from rootPP in rootPPs select CofeServices.EntryConstructor.ConstructPropertyHost(rootPP)).ToArray();
            //    using (var r = CofeDBServices.RepositoryFactory.CreateRepository())
            //    {
            //        r.Remove(
            //        r.SaveChanges();
            //    }
            //}
        }
    }
}
